//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.IO.Packaging;
using OpenLS.Core.Serialization;
using OpenLS.Drawing;
using OpenLS.Drawing.Serialization;

namespace OpenLS.Drawing.Media
{
    public class VideoFile : MediaObject
    {
        private OfficeArtExtensionList extLst;
        private string target;
        internal const string xmlName = "videoFile";

        public override void ReadXml(ReadContext context)
        {
            using (var c = context.Read(DrawingConstants.DrawingNamespace+ xmlName))
            {
                string rid = c.GetString(OfficeConstants.RelationshipNamespace + "link");
                target = c.Part.GetRelationship(rid).TargetUri.ToString();
                this.extLst = c.ReadOptionalElement<OfficeArtExtensionList>("extLst");
            }
        }

        public override void WriteXml(WriteContext context)
        {
            using (var c = context.Write(DrawingConstants.DrawingNamespace + xmlName))
            {
                var r = c.CreateExternalRelationship(target, DrawingConstants.videoRelationship);
                c.SetString(OfficeConstants.RelationshipNamespace + "link", r.Id);
                c.WriteOptionalElement(this.extLst);
            }
        }
    }
}